<template>
  <div class="survey-statistics">
    <div class="left-content">
      <!-- 第一模块 -->
      <div class="header-module">
        <h2>调查统计
        <span class="subtitle">互动问答板块包含所有学院课程的完整学习。</span>
      </h2>
      </div>

      <!-- 第二模块 -->
      <div class="secondary-nav-module">
        <nav class="secondary-nav">
          <router-link to="/survey/surveyall" class="nav-item" active-class="active">全部</router-link>
          <router-link to="/survey/surveysubmitted" class="nav-item" active-class="active">已提交</router-link>
          <router-link to="/survey/surveynot-submitted" class="nav-item" active-class="active">未提交</router-link>
        </nav>
      </div>

      <!-- 第三模块 -->
      <div class="main-content">
        <div class="content">
          <router-view></router-view>
        </div>
      </div>
    </div>
    
    <!-- 侧边栏 -->
    <div class="sidebar">
      <div class="placeholder-image">
        <img src="./survey/插画.png" alt="插图">
      </div>
      <div class="progress-section">
        <div class="progress-header">
          <h3>学习进度</h3>
          <p class="progress-text">已完成 {{ completedUnits }}/{{ totalUnits }} 单元</p>
        </div>
        <div class="progress-bar-container">
          <div class="progress-bar" :style="{ width: progressPercentage + '%' }"></div>
        </div>
      </div>
      <div class="related-courses">
        <h3>所属课程</h3>
        <button @click="goToCourseResource">游戏策划</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'SurveyStatistics',
  data() {
    return {
      completedUnits: 3,
      totalUnits: 6
    };
  },
  computed: {
    progressPercentage() {
      return (this.completedUnits / this.totalUnits) * 100;
    }
  },
  mounted() {
    this.fetchProgressData();
  },
  methods: {
    fetchProgressData() {
      axios.get('/api/progress') // 替换为你的API端点获取学习进度
        .then(response => {
          const data = response.data;
          this.completedUnits = data.completedUnits;
          this.totalUnits = data.totalUnits;
        })
        .catch(error => {
          console.error('Error fetching progress data:', error);
        });
    },
    goToCourseResource() {
      this.$router.push({ path: '/course-resource' });
    }
  }
};
</script>

<style scoped>
.survey-statistics {
  display: flex;
  margin: 0 150px 0 150px;
padding: 20px;
  background-color: #f9f9f9;
  justify-content: space-between;
}

/* 左侧内容样式 */
.left-content {
  flex: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-start; /* 将左侧内容靠左对齐 */
  margin-right: 50px; /* 确保左侧内容和右侧栏之间有间距 */
}

/* 第一模块样式 */
.header-module {
  width: 100%; /* 确保宽度与其他模块一致 */
  text-align: left;

}

h2 {
  margin: 0px 0px 10px 0px;
  font-size: 32px;
  text-align: left;

border: none;
color:rgba(0, 0, 0, 1);
font-weight: bold;
margin-top: 30px;
}

.subtitle {
  font-size: 14px;
  color: #888;
}

/* 第二模块样式 */
.secondary-nav-module {
  width: 96%; /* 确保宽度与其他模块一致 */
  padding: 20px;
  background-color: #ffffff;
  margin-bottom: 0px;
  border: 1px solid #ffffff;
  border-radius: 0px; /* 设置四个角为直角 */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  text-align: left;
  margin-top: 20px;
}

.secondary-nav {
  font-size: 16px;
  color: #888;
}

.nav-item {
  padding: 10px 15px;
  color: #000;
  text-decoration: none;
  white-space: nowrap;
  font-weight: bold;
}

.nav-item.active {
  color: #007bff;
  border-bottom: 2px solid #007bff;
}

/* 第三模块样式 */
.main-content {
  width: 100%; /* 确保宽度与其他模块一致，并与左边对齐 */
  margin: 0px 40px 0px 0px;
  
}

.content {
  margin-top: 20px;
  text-align: left;
}

/* 侧边栏样式 */
.sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.placeholder-image {
  height: 193px; /* Adjust the height as per your requirement */
  width: 260px; /* Set a fixed width */
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 50px;

}
img{
  max-width: 100%; /* 图片最大宽度为父元素宽度 */
  height: auto; /* 自动调整高度以保持比例 */
}
.progress-section {
  padding: 20px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-text {
  margin: 0;
  color: #888;
  font-size: 14px; /* Smaller font size */
}

.progress-bar-container {
  width: 100%;
  height: 10px;
  background-color: #e0e0e0;
  border-radius: 5px;
  margin-top: 10px;
}

.progress-bar {
  height: 100%;
  background-color: #007bff;
  border-radius: 5px;
}

.related-courses {
  padding: 20px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.related-courses h3 {
  text-align: left; /* Ensure left alignment */
  margin-top: 0;
}

.related-courses button {
  text-align: left; /* Ensure left alignment */
  font-size: 16px; /* Update font size if needed */
  margin: 0;
  color: #007bff;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: block; /* Ensure block display */
  width: 100%; /* Ensure full width */
}

.related-courses button:hover {
  text-decoration: underline;
}
</style>